#include <cstdio>
#include <algorithm>
using namespace std;
#define DEBUG
const int N=1e5+10;
struct Fruit
{
    int w, t;
    bool operator<(Fruit f)
    {
        if(t!=f.t) return t<f.t;
        else return w>f.w;
    }
}fruit[N];
int n, maxday, sum;

int main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        freopen("./out.txt", "w", stdout);
    #endif
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d %d", &fruit[i].w, &fruit[i].t), maxday=max(maxday, fruit[i].t);
    sort(fruit+1, fruit+1+n);
    int day=1, p=1;
    while(day<=maxday&&p<=n)
    {
        
        while(day>=fruit[p].t) p++;
        sum+=fruit[p].w;
        // printf("day:%d sum:%d\n", day, sum);
        p++; //这个水果已经卖出
        day++;
    }
    printf("%d\n", sum);
    return 0;
}